import {
	defineStore
} from 'pinia'

import {
	ref
} from 'vue'

export const useSearchStore = defineStore('search', () => {
		// 存储用户搜索历史记录
		const searchHistoryData = ref([])

		// 将获取到的信息存入历史记录
		const setSearchHistoryData = (data) => {
			searchHistoryData.value.push(data)
		}

		// 清空历史记录
		const clearSearchHistoryData = () => {
			searchHistoryData.value = []
		}

		return {
			searchHistoryData,
			setSearchHistoryData,
			clearSearchHistoryData
		}
	},
	// 持久化
	{
		persist: {
			storage: {
				getItem(key) {
					return uni.getStorageSync(key)
				},
				setItem(key, value) {
					return uni.setStorageSync(key, value)
				}
			}
		}
	})